package com.listener;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.PropertyConfigurator;

import com.common.LOG;

public class FBListener implements ServletContextListener {
	public void contextDestroyed(ServletContextEvent arg0) {

    }

    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        init(context);
    }
    protected void init(ServletContext context) {
    	log("初始化FB Log4j 开始!");
        initLog4j(context);
        log("初始化FB Log4j 结束!");
    }
    
    /**
     * init log4j
     * @param context
     * @throws AppComException
     */
    protected void initLog4j(ServletContext context){
        String resource="/log4j.properties";
        Properties prop = new Properties();
        try {
            prop.load(this.getClass().getResourceAsStream(resource));
        } catch (IOException e) {
            e.printStackTrace();
        }
        PropertyConfigurator.configure(prop);
    }
    private void log(String info){
        LOG.FBINFO("*******startup----->"+info);
    }
}